/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tsb.dominio.dispositivos.coneccion;

import java.util.ArrayList;
import java.util.Iterator;
import tsb.dominio.interfaces.IP;
import tsb.dominio.interfaces.InterfaceDeConeccion;
import tsb.dominio.network.RedRIP;

/**
 *
 * @author Fede
 */
public class Router extends DispositivoConeccion
{
    private String hostName;
    private IP ip;
    private ArrayList<IP> listaRedes; 
    //queda tipo de routing
    //queda NVRAM y Startup y Running Config



    public Router(int x, int y,String nombreAMostrar)
    {
        this.x=x;
        this.y=y;
        this.nombreAMostrar=nombreAMostrar;
        listaRedes = new ArrayList<IP>();
    }
    public Router(int x, int y, String hostName, IP ip, boolean estado, ArrayList<tsb.dominio.interfaces.InterfaceDeConeccion> interfaces, String nombreAMostrar)
    {
        this.hostName= hostName;
        this.ip=ip;
        this.x=x;
        this.y=y;
        this.estado=estado;
        this.interfaces=interfaces;
        this.nombreAMostrar=nombreAMostrar;
        listaRedes = new ArrayList<IP>();

    }
    
    public Router(int x, int y,String nombreAMostrar, ArrayList<tsb.dominio.interfaces.InterfaceDeConeccion> interfaces)
    {
        this.x=x;
        this.y=y;
        this.nombreAMostrar=nombreAMostrar;
        this.interfaces=interfaces;

    }
    
    public void addRed(IP red)
    {
        this.listaRedes.add(red);
    }
    
    public void removerRed(String red)
    {
        Iterator iter = this.listaRedes.iterator();
        
        while(iter.hasNext())
        {
            RedRIP r=(RedRIP) iter.next();
            if(r.getSalida().toString().compareTo(red)==0)
            {
                listaRedes.remove(r);
                break;
            }
        }
    }
    
    public void removerRed(RedRIP red)
    {
        this.removerRed(red.getDestino().toString());
    }

    public String getHostName()
    {
        return hostName;
    }

    public void setHostName(String hostName)
    {
        this.hostName = hostName;
    }

    public IP getIp()
    {
        return ip;
    }

    public void setIp(IP ip)
    {
        this.ip = ip;
    }

    public ArrayList<tsb.dominio.interfaces.InterfaceDeConeccion> getInterfaces()
    {
        return this.interfaces;
    }
    
    public String toString()
    {
         String cad= " --- Router ---\n"+
                    "Nombre a Mostrar: " + this.nombreAMostrar + "\n"+
                    "Estado: " + this.estado + "\n"+
                    "IP: " + this.ip + "\n"+
                    "Hostname: " + this.hostName + "\n"+
                    "Interfaces: " + this.interfaces + "\n"+
                    "Ubicacion: x=" + this.x + " y="+this.y+"\n";

            if(interfaces!=null)
            {
                Iterator iter= this.interfaces.iterator();
                    while(iter.hasNext())
                    {
                        InterfaceDeConeccion i = (InterfaceDeConeccion) iter.next();
                        cad=cad+i.toString();
                    }
            }
            return cad;
    }

    
}
